<template>
  <div>
    <div style="margin-bottom: 10px;margin-top: 10px;">
          <el-input v-model="createUserName"  placeholder="请输入法人姓名" suffix-icon="el-icon-search" style="width: 200px"
          @keyup.enter.native="loadPost"></el-input>
 
     
          <el-button type="primary" style="margin-left: 10px" @click="loadPost">查询</el-button>
          <el-button type="success" @click="resetParam">重置</el-button>

      </div>
  <el-table :data="tableData"
  :header-cell-style="{background:'#f2f5fc',color:'#555'}" border>
      <el-table-column prop="id" label="ID" width="230">
      </el-table-column>

      <el-table-column prop="name" label="成果名" width="230">
      </el-table-column>
 
      <el-table-column prop="role" label="归属"  width="160">
      </el-table-column>

      <el-table-column prop="bak" label="审核备注"  width="230" >
      </el-table-column>

      <el-table-column prop="status" label="状态"  width="160" :formatter="statusFormate">
      </el-table-column>

      <el-table-column prop="operate" label="操作">
          <template slot-scope="scope">
          <el-button size="small" type="success" @click="mod(scope.row)">审核</el-button>
              
        
          </template>
      </el-table-column>

  </el-table>
      <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pagenum"
              :page-sizes="[2, 5, 10, 20]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
      </el-pagination>

      
      <el-dialog
              title="提示"
              :visible.sync="centerDialogVisible"
              width="80%"
              center>
<!--           //增加表单-->
          <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
    

              <el-form-item label="成果名" prop="name">
                      <el-input  v-model="form.name"></el-input>
              </el-form-item>

              <el-form-item label="归属" prop="role">
                      <el-input  v-model="form.role"></el-input>
              </el-form-item>

              <el-form-item label="备注" prop="bak">
                      <el-input  v-model="form.bak"></el-input>
              </el-form-item>

              <el-form-item label="标签">
                  <el-select v-model="form.status" placeholder="请选择状态">
                  <el-option label="申请中" value="1"></el-option>
                  <el-option label="审核通过" value="2"></el-option>
                  <el-option label="审核未通过" value="3"></el-option>
                   </el-select>
                </el-form-item>
             

          </el-form>

          <span slot="footer" class="dialog-footer">
            <el-button @click="centerDialogVisible = false">取 消</el-button>
           <el-button type="primary" @click="save">确 定</el-button>
            </span>
      </el-dialog>

  </div>
</template>

<script>
    export default {
        name: "UnitReviewed",
        data() {
         
            return {
                // 查询下拉框
                statuss: [{
          value: -1,
          label: '全部状态'
        }, {
          value: 1,
          label: '申请中'
        }, {
          value: 2,
          label: '审核通过'
        }, {
          value: 3,
          label: '审核未通过'
        }],
        status: -1,
        role:-1,
        roles:[{
            value: -1,
            label: '会员+非会员'
            }, {
              value:0,
              label: '会员'
                },
                {
              value: 1,
              label: '非会员'
                }],
                createUserName:"",
              tableData: [],
              pagenum:1,
              pageSize:2,
              total:0,
              name:'',
              
                centerDialogVisible:false,
                session:'',
                form:{
                    id:'',
                    name:'',
                    role:'',
                    bak:'',
                    status:'',
                    createUserId:'',
                    createUserName:''
                 
                },
                rules: {
                   
                    name: [
                        { required: true, message: '请输入名字', trigger: 'blur' },
                    ],
                   

                }

            }

        },
        created(){
            this.session = JSON.parse(sessionStorage.getItem('CurUser'))
            this.form.createUserId=this.session.createUserId
            this.form.createUserName=this.session.createUserName
           
        },
        methods:{
             // 显示状态
             statusFormate(row, index){
                if(row.status == 1){
                    return "申请中";
                }else if(row.status == 2){
                    return "审核通过";
                }else if(row.status == 3){
                    return "审核未通过";
                }
            },
            mod(row){
                console.log(row)
            //    赋值到表单

                this.centerDialogVisible=true
                this.$nextTick(()=>{
                    this.form.id = row.id
                    this.form.name = row.name
                    this.form.status = row.status
                    this.form.bak = row.bak
                    this.form.role = row.role
      
                 
                    //    这个在第一次的时候不能使用，所以需要nextTick异步
                })
            },

       
            // 审核
            doMod(){
                this.$axios.put(this.$httpUrl+'/jk/admin/achievement/updateStatus?status='+this.form.status+'&id='+this.form.id).then(res=>res.data).then(res=>{

                    if (res.resCode=='000000'){
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                        //成功之后离开刷新页面

                        this.centerDialogVisible=false
                        this.loadPost()
                        // this.resetForm()

                    }else{
                        this.$message({
                            message: '操作失败',
                            type: 'error'
                        });
                    }

                })
            },
        
            save(){
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        if (this.form.id){
                            this.doMod()
                        }

                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            },
            handleSizeChange(val) {
                
                this.pagenum=1
                this.pageSize=val
                this.loadPost()
            },
            handleCurrentChange(val) {
                
                this.pagenum=val
                this.loadPost()
            },
          
            resetParam(){
                this.createUserName='',
                this.status=-1,
                this.role=-1
                
            },
            loadPost(){
             
             this.$axios.get(this.$httpUrl+'/jk/admin/achievement/listT?createUserName='+this.createUserName+'&pagenum='+this.pagenum +'&pageSize='+this.pageSize
             ).then(res=>res.data).then(res=>{
                 if (res.resCode=='000000'){
                     this.tableData=res.data.records
                     this.total=res.data.total

                 }else{
                     alert('获取数据失败')
                 }

             })
         }},
        beforeMount() {
            
            this.loadPost();

        }
    }
</script>

<style>

</style>